<?php

namespace App\Domain\Visitlist\Controllers;

use App\Domain\Visitlist\Requests\createVisitlistPost;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Domain\Visitlist\Services\VisitlistService;
use App\Supports\Constant\PaginationConst;
use App\Supports\Formatter\ResponseFormatter;
use Illuminate\Pagination\LengthAwarePaginator;

class VisitlistController extends Controller
{
    //就诊记录
    public function list(Request $request,VisitlistService $visitlistService){
        $params = [
            'uid' => $request['memberUid'],
            'currentPage' => $request->input('currentPage', 1),
            'pageSize' => $request->input('pageSize', PaginationConst::PAGE_SIZE),
        ];
        $visitPaginator = $visitlistService->list($params);
        $visitPaginator = new LengthAwarePaginator($visitPaginator->items(), $visitPaginator->total(), $visitPaginator->perPage(), $visitPaginator->currentPage());
        //格式化
        $keyMap = [
            'uid' => 'uid',
            'date' => 'date',
            'hospital' => 'hospital',
            'room' => 'room',
            'description' => 'description',
            'diagnosis' => 'diagnosis',
            'diseaseName' => 'diseaseName',
            'type'=>'',
            'files'=>'',
        ];
        return $this->success(ResponseFormatter::formatterPaginator($visitPaginator, $keyMap));
    }

    //保存就诊记录
    public function saveVisit(createVisitlistPost $request,VisitlistService $visitlistService){
        $param = $request->validated();
        $data = $visitlistService->create($param);
        return $this->success($data);
    }
}
